package br.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import br.com.bean.TipoRecuperacaoBean;

public class TipoRecuperacaoDao {

public void inserir (Connection conn, TipoRecuperacaoBean value) throws Exception{
		
		String sql = "INSERT INTO tipo_recuperacao(tipo_rec) VALUES (?)";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, value.getDescricao());
		ps.execute();
		ps.close();
		
	}
	
	public void alterar (Connection conn, TipoRecuperacaoBean value) throws Exception{
		
		String sql = "UPDATE tipo_recuperacao SET tipo_rec=? WHERE id = ?;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, value.getDescricao());
		ps.execute();
		ps.close();

	}
	
	public void excluir (Connection conn, TipoRecuperacaoBean value) throws Exception {

		String sql = "DELETE * FROM tipo_recuperacao WHERE id = ?;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, value.getId());
		ps.executeUpdate();
	}
	
	public ArrayList<TipoRecuperacaoBean> getLista(Connection conn, TipoRecuperacaoBean value) throws Exception{

		String sql = "SELECT tipo_rec FROM tipo_recuperacao where id = ?;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, value.getId());
		ResultSet rs = ps.executeQuery();
		ArrayList<TipoRecuperacaoBean> na = new ArrayList<TipoRecuperacaoBean>();
		while(rs.next()){
			TipoRecuperacaoBean a = new TipoRecuperacaoBean();
			a.setDescricao(rs.getString("tipo_rec"));
			na.add(a);
		}
		return na;
	}

	public ArrayList<TipoRecuperacaoBean> getLista(Connection conn) throws Exception{

		String sql = "SELECT tipo_rec FROM tipo_recuperacao;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		ArrayList<TipoRecuperacaoBean> na = new ArrayList<TipoRecuperacaoBean>();
		while(rs.next()){
			TipoRecuperacaoBean a = new TipoRecuperacaoBean();
			a.setDescricao(rs.getString("tipo_rec"));
			na.add(a);
		}
		return na;
	}	
}
